package com.logic.landseaserver.service.impl;

import com.logic.common.security.SecurityUtils;
import com.logic.landseaserver.domain.CustomerCard;
import com.logic.landseaserver.persistence.read.CustomerCardReadMapper;
import com.logic.landseaserver.persistence.write.CustomerCardWriteMapper;
import com.logic.landseaserver.ws.dto.CustomerCardDTO;
import com.logic.landseaserver.service.ICustomerCardService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;

/**
 * Created by Junny on 2018/8/8.
 */
@Service
public class CustomerCardService implements ICustomerCardService{

    private static final Logger LOG = LoggerFactory.getLogger(CustomerCardService.class);
    @Autowired
    private CustomerCardWriteMapper customerCardWriteMapper;
    @Autowired
    private CustomerCardReadMapper customerCardReadMapper;

    @Override
    public void updateCustomerCard(CustomerCardDTO customerCardDTO) {

        if(customerCardDTO.getSourceId()==null || StringUtils.isEmpty(customerCardDTO.getSourceType())||
                StringUtils.isEmpty(customerCardDTO.getCardAccount()) ||   StringUtils.isEmpty(customerCardDTO.getCardUserName())||
                StringUtils.isEmpty(customerCardDTO.getCellPhone()) ||   StringUtils.isEmpty(customerCardDTO.getBankName())||
                StringUtils.isEmpty(customerCardDTO.getBankBrname()) ||   StringUtils.isEmpty(customerCardDTO.getCardNo())){
            LOG.info("银行卡信息不做修改，银行卡信息不能为空");
            return;
        }
        CustomerCard card = new CustomerCard();
        card.setSourceId(customerCardDTO.getSourceId());
        card.setSourceType(customerCardDTO.getSourceType());
        card.setCardAccount(customerCardDTO.getCardAccount());
        card.setCardUserName(customerCardDTO.getCardUserName());
        card.setCellPhone(customerCardDTO.getCellPhone());
        card.setBankName(customerCardDTO.getBankName());
        card.setBankBrname(customerCardDTO.getBankBrname());
        card.setCardNo(customerCardDTO.getCardNo());
        card.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
        customerCardWriteMapper.updateBySInfo(card);
    }

    @Override
    public void updateCustomerCard(CustomerCard customerCardDTO) {
        if(customerCardDTO.getSourceId()==null || StringUtils.isEmpty(customerCardDTO.getSourceType())||
                StringUtils.isEmpty(customerCardDTO.getCardAccount()) ||   StringUtils.isEmpty(customerCardDTO.getCardUserName())||
                StringUtils.isEmpty(customerCardDTO.getCellPhone()) ||   StringUtils.isEmpty(customerCardDTO.getBankName())||
                StringUtils.isEmpty(customerCardDTO.getBankBrname()) ||   StringUtils.isEmpty(customerCardDTO.getCardNo())){
            LOG.info("银行卡信息不做修改，银行卡信息不能为空");
            return;
        }
        customerCardDTO.updateCommonInfo(SecurityUtils.getCurrentLogin().getUserId());
        customerCardWriteMapper.updateBySInfo(customerCardDTO);
    }

    @Override
    public CustomerCardDTO queryCardInfo(HashMap map){
        return customerCardReadMapper.queryCardInfo(map);
    }

    @Override
    public int insertCustomerCard(CustomerCardDTO customerCardDTO) {
        return 0;
    }
}
